package org.ricks.net.action.context.session;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;

public abstract class Session {

    private static final AtomicLong ATOMIC_LONG = new AtomicLong(0);

    private final long sid = ATOMIC_LONG.incrementAndGet();

    public abstract void writeBinary(byte[] data); // 发送二进制数据
    abstract void writeText(String text);   // 发送文本数据（WebSocket 专用）
    abstract void close();                  // 关闭会话
    abstract public  <R> CompletableFuture<R> invoke(short cmd, Object body, Class<R> resultType);
    abstract public <R> CompletableFuture<R> invoke(short cmd, Object body, Class<R> resultType, long timeout, TimeUnit unit);

    public long getSid() {
        return sid;
    }
}
